import requests
import re

id = 1
username = 'zy01'
password = '123456'
vericode = 'shtd'
url=r'http://172.16.22.108:8080'
#首页
url_first=rf'{url}/bsams/front/login.do'
url_vericode=rf'{url}/bsams/front/vericode.do'
url_info=rf'{url}/bsams/front/asset/asset_list.do'
headers={
    'Content-Type':'application/x-www-form-urlencoded'
}

# 构造 data
data = {
    'taskId': id,
    'loginName': username,
    'password': password,
    'vericode': vericode
}
#发送请求
s=requests.Session()
s.get(url_first)
s.get(url_vericode)
s.post(url_first,data=data)
# 访问 资产管理页
resp = s.get(url_info)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
data_asset_add={
    'title':'资产新增名称',
    'storageId':'电脑设备库',
    'providerId':'辽宁异界公司'
}
#资产新增
url_add=rf'{url}/bsams/front/asset/asset_new.do'
s.get(url_add)
resp=s.post(url_add,data=data_asset_add)
patt=r'<title>(.*?)</title>'
title=re.findall(patt,resp.text)
print(title)

#打开修改资产页
data_asset_open={'id':'1804'}
data_asset_mod = {
    'title': '修改资产名称',
    'storageId': '维信科技发展有限公司',
    'providerId': '总经理办公室'
}
url_mod=rf'{url}/bsams/front/asset/asset_update.do'
resp=s.get(url_mod,params=data_asset_open)
s.post(url_add,data=data_asset_mod)
patt=r'<title>(.*?)</title>'
title=re.findall(patt,resp.text)
print(title)
#资产借用页
url_borrow=rf'{url}/bsams/front/asset/asset_borrow.do'
data_asset_open={'id':'1804'}
data_asset_borrow = {
    'id': '1804',
    'departId': '财务部',
    'remark': '备注备注'
}

resp = s.get(url_borrow, params=data_asset_open)
s.post(url_add,data=data_asset_borrow)
patt=r'<title>(.*?)</title>'
title=re.findall(patt,resp.text)
print(title)

# 资产归还
url_asset_return = rf'{url}/bsams/front/asset/asset_giveBack.do'
asset_return_id = {'assetId': '1720'}

resp = s.post(url_asset_return, data=asset_return_id)

# 查询存放地点
url_location = rf'{url}/bsams/front/asset_storage/asset_storage_list.do'
location_data = {
    'pageNo': '',
    'status': '',
    'title': ''

}
resp = s.post(url_location, data=location_data)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 查询供应商
url_supplier = rf'{url}/bsams/front/asset_provider/asset_provider_list.do'
supplier_data = {
    'pageNo': '',
    'status': '',
    'title': ''

}
resp = s.post(url_supplier, data=supplier_data)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 查询个人信息
url_user = rf'{url}/bsams/front/asset_user/user_info.do'

resp = s.get(url_user)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 修改手机号
url_phone = rf'{url}/bsams/front/asset_user/update_phone.do'
phone_data = {
    'assetUserId': '230',
    'phone': '17534741512'
}
resp = s.post(url_phone, data=phone_data)

# 修改密码
url_pwd = rf'{url}/bsams/front/asset_user/update_password_pre.do'
pwd_id = {'assetUserId': '230'}
resp = s.get(url_user, params=pwd_id)
pwd_data = {
    'assetUserId': '123456',
    'oldPassword': '123456',
    'newPassword': '123456'
}
s.post(url_pwd, data=pwd_data)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)